<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>JavaScript 第三天 | XC's Blog</title><meta name="keywords" content="JavaScript笔记"><meta name="author" content="XC's Blog"><meta name="copyright" content="XC's Blog"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="JavaScript 基础第三天 — for 循环 和 array数组1. for循环基本使用: for循环也是重复执行代码  好处: 把声明起始值、循环条件、变化值写到一起，一目了然  如果明确循环次数的时候使用for循环  不明确循环次数的时候使用while循环 123for (声明变量; 循环条件; 变化值) &amp;#123;    &#x2F;&#x2F; 循环体&amp;#125;  for 输出1到100偶数之间的和"><meta property="og:type" content="article"><meta property="og:title" content="JavaScript 第三天"><meta property="og:url" content="https://webxc.eu.org/post/6e+47/index.html"><meta property="og:site_name" content="XC&#39;s Blog"><meta property="og:description" content="JavaScript 基础第三天 — for 循环 和 array数组1. for循环基本使用: for循环也是重复执行代码  好处: 把声明起始值、循环条件、变化值写到一起，一目了然  如果明确循环次数的时候使用for循环  不明确循环次数的时候使用while循环 123for (声明变量; 循环条件; 变化值) &amp;#123;    &#x2F;&#x2F; 循环体&amp;#125;  for 输出1到100偶数之间的和"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://npm.elemecdn.com/webxc/cover/js1.webp"><meta property="article:published_time" content="2022-12-27T23:30:00.000Z"><meta property="article:modified_time" content="2023-08-30T18:00:49.037Z"><meta property="article:author" content="XC&#39;s Blog"><meta property="article:tag" content="JavaScript笔记"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://npm.elemecdn.com/webxc/cover/js1.webp"><link rel="shortcut icon" href="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><link rel="canonical" href="https://webxc.eu.org/post/6e+47/"><link rel="preconnect" href="//cdn.jsdelivr.net"><link rel="preconnect" href="//busuanzi.ibruce.info"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://npm.elemecdn.com/@fortawesome/fontawesome-free@6.2.0/css/all.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.css" media="print" onload='this.media="all"'><script>const GLOBAL_CONFIG={root:"/",algolia:void 0,localSearch:{path:"/search.xml",preload:!1,languages:{hits_empty:"找不到您查询的内容：${query}"}},translate:void 0,noticeOutdate:void 0,highlight:{plugin:"highlighjs",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:!1},copy:{success:"吾辈宣布,你的剪切板已被占领",error:"呀~复制失败,请在尝试下",noSupport:"对不起,你的浏览器不支持"},relativeDate:{homepage:!1,post:!1},runtime:"",date_suffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{limitCount:60,languages:{author:"作者: XC's Blog",link:"链接: ",source:"来源: XC's Blog",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"您已切换为繁体",cht_to_chs:"您已切换为简体",day_to_night:"您已切换为深色主题",night_to_day:"您已切换为浅色主题",bgLight:"#3b70fc",bgDark:"#121212",position:"bottom-center"},source:{justifiedGallery:{js:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.min.js",css:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.css"}},isPhotoFigcaption:!1,islazyload:!0,isAnchor:!0}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={title:"JavaScript 第三天",isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2023-08-30 18:00:49"}</script><noscript><style>#nav{opacity:1}.justified-gallery img{opacity:1}#post-meta time,#recent-posts time{display:inline!important}</style></noscript><script>(e=>{e.saveToLocal={set:function(e,t,o){if(0===o)return;const n=864e5*o,a={value:t,expiry:(new Date).getTime()+n};localStorage.setItem(e,JSON.stringify(a))},get:function(e){const t=localStorage.getItem(e);if(!t)return;const o=JSON.parse(t);if(!((new Date).getTime()>o.expiry))return o.value;localStorage.removeItem(e)}},e.getScript=e=>new Promise(((t,o)=>{const n=document.createElement("script");n.src=e,n.async=!0,n.onerror=o,n.onload=n.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(n.onload=n.onreadystatechange=null,t())},document.head.appendChild(n)})),e.activateDarkMode=function(){document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")},e.activateLightMode=function(){document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#ffffff")};const t=saveToLocal.get("theme");"dark"===t?activateDarkMode():"light"===t&&activateLightMode();const o=saveToLocal.get("aside-status");void 0!==o&&("hide"===o?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"));/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})(window)</script><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mgi.css"><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mg111.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.16/css/mg2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styless.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styles.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/font.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.15/css/font2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiperstyle.css" media="print" onload='this.media="all"'><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">95</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.webxc.eu.org/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image:url('https://npm.elemecdn.com/webxc/cover/js1.webp')"><nav id="nav"><span id="blog_name"><div class="back-home-button" tabindex="-1"><i class="back-home-button-icon fas fa-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">项目</div><div class="back-menu-list"><a class="back-menu-item" href="/" title="前往博客主页" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">主站</span></a><a class="back-menu-item" href="https://e.webxc.eu.org/" rel="external nofollow" title="前往学习笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">学习笔记</span></a><a class="back-menu-item" href="https://v.webxc.eu.org/" rel="external nofollow" title="VuePress学习文档" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">VuePress文档</span></a><a class="back-menu-item" href="https://b.webxc.eu.org/" rel="external nofollow" title="旧站Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">旧站Hexo</span></a><a class="back-menu-item" href="https://gridea.webxc.eu.org/" rel="external nofollow" title="Gridea笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gridea笔记</span></a><a class="back-menu-item" href="https://c.webxc.eu.org/" rel="external nofollow" title="魔改Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">魔改Hexo</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">博客镜像</div><div class="back-menu-list"><a class="back-menu-item" href="https://blog.webxc.eu.org/" title="Vercel镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Vercel镜像</span></a><a class="back-menu-item" href="https://webxc.tk/" title="Netlify镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Netlify镜像</span></a><a class="back-menu-item" href="https://web-xc.gitee.io/" title="Gitee镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gitee镜像</span></a><a class="back-menu-item" href="https://cf.webxc.eu.org/" title="Cloudflare镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Cloudflare镜像</span></a><a class="back-menu-item" href="https://render.webxc.eu.org/" title="Render镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Render镜像</span></a></div></div></div></div><a id="site-name" href="/"><div class="title">XC's Blog</div><i class="fa-solid fa-house"></i></a></span><div class="mask-name-container"><center id="name-container"><a id="page-name" href="javascript:btf.scrollToDest(0, 500)">PAGE_NAME</a></center></div><div id="menus"><div class="nav-button" id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i> <span>搜索</span></a></div><div class="nav-button" id="darkmode_navswitch"><a class="darkmode_switchbutton" type="button" title="浅色和深色模式转换" onclick="switchDarkMode()"><i class="fas fa-adjust"></i></a></div><div class="nav-button" id="nav-totop"><a class="totopbtn"><i class="fas fa-arrow-up"></i><span id="percent" onclick="btf.scrollToDest(0,500)">0</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.webxc.eu.org/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">JavaScript 第三天</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-12-27T23:30:00.000Z" title="发表于 2022-12-27 23:30:00">2022-12-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-08-30T18:00:49.037Z" title="更新于 2023-08-30 18:00:49">2023-08-30</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/JavaScript%E7%AC%94%E8%AE%B0/">JavaScript笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span data-flag-title="JavaScript 第三天"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="twikoo_visitors"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="JavaScript-基础第三天-—-for-循环-和-array数组"><a href="#JavaScript-基础第三天-—-for-循环-和-array数组" class="headerlink" title="JavaScript 基础第三天 — for 循环 和 array数组"></a>JavaScript 基础第三天 — for 循环 和 array数组</h3><h3 id="1-for循环基本使用"><a href="#1-for循环基本使用" class="headerlink" title="1. for循环基本使用:"></a>1. for循环基本使用:</h3><ol><li><p>for循环也是重复执行代码</p></li><li><p>好处: 把声明起始值、循环条件、变化值写到一起，一目了然</p></li><li><p>如果明确循环次数的时候使用for循环</p></li><li><p>不明确循环次数的时候使用while循环</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (声明变量; 循环条件; 变化值) &#123;</span><br><span class="line">    <span class="comment">// 循环体</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li><li><p>for 输出1到100偶数之间的和</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num2 = <span class="number">1</span>; num2 &lt;= <span class="number">100</span>; num2++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num2 % <span class="number">2</span> === <span class="number">0</span>) &#123;</span><br><span class="line">        num1 += num2</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li><li><p>for循环 最大优势是<strong>遍历数组</strong></p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="string">&#x27;pink&#x27;</span>, <span class="string">&#x27;blue&#x27;</span>, <span class="string">&#x27;green&#x27;</span>]</span><br><span class="line"><span class="comment">// num1.length和&lt;=3的区别</span></span><br><span class="line"><span class="comment">// for (let num2 = 0; num2 &lt;= 3; num2++) &#123;</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num2 = <span class="number">0</span>; num2 &lt; num1.<span class="property">length</span>; num2++) &#123;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(num1[num2])</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li></ol><h3 id="2-循环退出"><a href="#2-循环退出" class="headerlink" title="2. 循环退出:"></a>2. 循环退出:</h3><ol><li><p>continue：结束本次循环，继续下次循环</p></li><li><p>break：直接结束本次循环</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num1= <span class="number">1</span>; num1 &lt;= <span class="number">6</span>; num1++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num1 === <span class="number">3</span>) &#123;</span><br><span class="line">        <span class="comment">// continue 退出本次循环, 继续下次循环</span></span><br><span class="line">        <span class="comment">// break 直接结束本次循环  </span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(num1)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li></ol><h3 id="3-for-循环嵌套"><a href="#3-for-循环嵌套" class="headerlink" title="3. for 循环嵌套:"></a>3. for 循环嵌套:</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">一个循环里再套一个循环，一般用在<span class="keyword">for</span>循环里</span><br><span class="line"><span class="keyword">for</span> (外部声明变量; 循环条件 变化值) &#123;</span><br><span class="line">    <span class="keyword">for</span> (内部声明变量; 循环条件; 变化值) &#123;</span><br><span class="line">        <span class="comment">// 循环体</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ol><li>使用 for 嵌套 用户输入后打印几行几列星星</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入多少列个星&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> num2 = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入多少行个星&#x27;</span>)</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num3 = <span class="number">1</span>; num3 &lt;= num1; num3++) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">let</span> num4 = <span class="number">1</span>; num4 &lt;= num2; num4++) &#123;</span><br><span class="line">        <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">&#x27;❤&#x27;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">`&lt;br&gt;`</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ol start="2"><li>打印倒三角形星星, 外循环控制行, 内循环控制列打印几个 内循环个数跟第几行是一一对应的</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num1 = <span class="number">1</span>; num1 &lt;= <span class="number">5</span>; num1++) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">let</span> num2 = <span class="number">1</span>; num2 &lt;= num1; num2++) &#123;</span><br><span class="line">        <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">&#x27;💚&#x27;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">`&lt;br&gt;`</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ol start="3"><li>使用for 嵌套 打印九九乘法表</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num1 = <span class="number">1</span>; num1 &lt;= <span class="number">9</span>; num1++) &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">let</span> num2 = <span class="number">1</span>; num2 &lt;= num1; num2++) &#123;</span><br><span class="line">        <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">`<span class="subst">$&#123;num2&#125;</span> x <span class="subst">$&#123;num1&#125;</span> = <span class="subst">$&#123;num1 * num2&#125;</span>`</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">`&lt;br&gt;`</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><hr><h3 id="4-数组的基本使用"><a href="#4-数组的基本使用" class="headerlink" title="4. 数组的基本使用:"></a>4. 数组的基本使用:</h3><ol><li>数组(Array)是一种可以<strong>按顺序保存数据的数据类型</strong></li><li>在数组中，数据的编号也叫<strong>索引或下标</strong></li><li>数组是按顺序保存，每个数据都有自己的编号</li><li>数组可以存储<strong>任意类型的数据</strong></li><li>如果有多个数据可用数组保存</li><li>计算机中的编号从0开始，第一个编号为0，第二个编号为1，以此类推</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> 数组名 = [数据<span class="number">1</span>, 数据<span class="number">2</span>, 数据<span class="number">3</span>]</span><br></pre></td></tr></table></figure><ol><li><p>通过下标取数据</p></li><li><p>取出来什么类型，就根据这种类型特点来访问</p></li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]</span><br><span class="line">num[<span class="number">0</span>] num[<span class="number">1</span>] num[<span class="number">2</span>]</span><br></pre></td></tr></table></figure><ol><li><p>元素：数组中保存的每个数据都叫<strong>数组元素</strong></p></li><li><p>下标：数组中<strong>数据的编号</strong></p></li><li><p>长度：数组中<strong>数据的个数</strong>，通过数组的length属性获得</p></li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num [<span class="string">&#x27;pink&#x27;</span>, <span class="string">&#x27;blue&#x27;</span>, <span class="string">&#x27;green&#x27;</span>]</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num[<span class="number">0</span>]) <span class="comment">// pink</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num.<span class="property">length</span>) <span class="comment">// 3</span></span><br></pre></td></tr></table></figure><h3 id="5-for-遍历数组"><a href="#5-for-遍历数组" class="headerlink" title="5. for 遍历数组:"></a>5. for 遍历数组:</h3><ol><li>用循环把数组中每个元素都访问到,一般会用<strong>for循环遍历</strong></li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i &lt; 数组名.<span class="property">length</span>; i++) &#123;</span><br><span class="line">    <span class="comment">// 数组名[i]</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h5 id="1-使用for循环-求数组的-和-x2F-平均值"><a href="#1-使用for循环-求数组的-和-x2F-平均值" class="headerlink" title="1. 使用for循环 求数组的 和&#x2F;平均值"></a>1. 使用for循环 求数组的 和&#x2F;平均值</h5><ol><li>声明一个求和变量 num2</li><li>遍历这个数组，把里面每个数组元素加到 num2 里面</li><li>用求和变量 num2 除以数组的长度得到数组的平均值</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">2</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">7</span>, <span class="number">4</span>]</span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">0</span></span><br><span class="line"><span class="keyword">let</span> num3 = <span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> (num4 = <span class="number">0</span>; num4 &lt; num1.<span class="property">length</span>; num4++) &#123;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(num1[num4])</span><br><span class="line">    num2 += num1[num4]</span><br><span class="line">&#125;</span><br><span class="line">num3 = num2 / num1.<span class="property">length</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">`和是<span class="subst">$&#123;num2&#125;</span>,平均值是<span class="subst">$&#123;num3&#125;</span>`</span>)</span><br></pre></td></tr></table></figure><h5 id="2-使用for循环-求数组最大值"><a href="#2-使用for循环-求数组最大值" class="headerlink" title="2. 使用for循环 求数组最大值"></a>2. 使用for循环 求数组最大值</h5><ol><li>声明一个保存最大元素的变量 num2</li><li>默认最大值可以取数组中的第一个元素</li><li>遍历这个数组，把每个数组元素和 num2 相比较</li><li>如果这个数组元素大于num2 就把这个数组元素存到 num2 里面，否则继续下一轮比较</li><li>最后输出这个 num2</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">2</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">77</span>, <span class="number">52</span>, <span class="number">25</span>, <span class="number">7</span>]</span><br><span class="line"><span class="keyword">let</span> num2 = num1[<span class="number">0</span>]</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num3 = <span class="number">1</span>; num3 &lt; num1.<span class="property">length</span>; num3++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num2 &lt; num1[num3]) &#123;</span><br><span class="line">        num2 = num1[num3]</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(num2)</span><br></pre></td></tr></table></figure><h5 id="3-使用for循环-求数组中大于等于5的和-45"><a href="#3-使用for循环-求数组中大于等于5的和-45" class="headerlink" title="3. 使用for循环 求数组中大于等于5的和 45"></a>3. 使用for循环 求数组中大于等于5的和 45</h5><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">4</span>, <span class="number">9</span>, <span class="number">5</span>, <span class="number">20</span>, <span class="number">3</span>, <span class="number">11</span>]</span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num3 = <span class="number">0</span>; num3 &lt; num1.<span class="property">length</span>; num3++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num1[num3] &gt;= <span class="number">5</span>) &#123;</span><br><span class="line">        num2 += num1[num3]</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(num2)</span><br></pre></td></tr></table></figure><h5 id="4-使用for循环-计算以下数组中能被3整除的偶数的和-24"><a href="#4-使用for循环-计算以下数组中能被3整除的偶数的和-24" class="headerlink" title="4. 使用for循环 计算以下数组中能被3整除的偶数的和 24"></a>4. 使用for循环 计算以下数组中能被3整除的偶数的和 24</h5><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">2</span>, <span class="number">6</span>, <span class="number">18</span>, <span class="number">15</span>, <span class="number">40</span>]</span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num3 = <span class="number">0</span>; num3 &lt; num1.<span class="property">length</span>; num3++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num1[num3] % <span class="number">3</span> === <span class="number">0</span> &amp;&amp; num1[num3] % <span class="number">2</span> === <span class="number">0</span>) &#123;</span><br><span class="line">        num2 += num1[num3]</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><hr><h3 id="6-操作数组"><a href="#6-操作数组" class="headerlink" title="6. 操作数组:"></a>6. 操作数组:</h3><ol><li>数组本质是<strong>数据集合</strong>, 操作数据无非是<strong>增、删、改、查</strong></li><li>查: 查询数组数据, <strong>数组[下标]</strong>, 称为<strong>访问数组数据</strong></li><li>改: 重新赋值, <strong>数组[下标] &#x3D; 新值</strong></li><li>增: 数组添加新数据, <strong>arr.push(新增内容)、arr.unshift(新增内容)</strong></li><li>删: 删除数组中数据, <strong>arr.pop()、arr.shift()、arr.splice(操作下标,删除个数)</strong></li></ol><h4 id="1-增：数组增加新的数据"><a href="#1-增：数组增加新的数据" class="headerlink" title="1. 增：数组增加新的数据"></a>1. 增：数组增加新的数据</h4><ol><li>数组.push()：将一个或多个元素<strong>添加到数组的末尾</strong>，并<strong>返回该数组的新长度</strong> (重点💖)</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">1</span>, <span class="number">2</span>]</span><br><span class="line"><span class="comment">// push 添加新数组到末尾</span></span><br><span class="line">num1.<span class="title function_">push</span>(<span class="number">3</span>)</span><br></pre></td></tr></table></figure><ol start="2"><li>arr.unshift(新增的内容)：将一个或多个元素<strong>添加到数组的开头</strong>，并返回该数组的新长度</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">1</span>, <span class="number">2</span>]</span><br><span class="line"><span class="comment">// unshift 添加新数组到第一个</span></span><br><span class="line">num1.<span class="title function_">unshift</span>(<span class="number">3</span>)</span><br><span class="line"><span class="comment">// 添加一个新数组并返回数组的长度</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num1.<span class="title function_">push</span>(<span class="number">4</span>))</span><br></pre></td></tr></table></figure><h5 id="１-数组筛选-将数组中大于等于10的元素选出来-放入新数组"><a href="#１-数组筛选-将数组中大于等于10的元素选出来-放入新数组" class="headerlink" title="１. 数组筛选, 将数组中大于等于10的元素选出来, 放入新数组"></a>１. 数组筛选, 将数组中大于等于10的元素选出来, 放入新数组</h5><ol><li>声明一个新数组用于存放新数据 num2</li><li>遍历原来的旧数组, 找出大于等于10的元素</li><li>依次追加给新数组num2</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">2</span>, <span class="number">0</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">77</span>, <span class="number">0</span>, <span class="number">52</span>, <span class="number">0</span>, <span class="number">25</span>, <span class="number">7</span>]</span><br><span class="line"><span class="keyword">let</span> num2 = []</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num3 = <span class="number">0</span>; num3 &lt; num1.<span class="property">length</span>; num3++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num1[num3] &gt;= <span class="number">10</span>) &#123;</span><br><span class="line">        num2.<span class="title function_">push</span>(num1[num3])</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(num2)</span><br></pre></td></tr></table></figure><h5 id="2-数组去0-将数组中0去掉-形成不包含0的新数组"><a href="#2-数组去0-将数组中0去掉-形成不包含0的新数组" class="headerlink" title="2. 数组去0, 将数组中0去掉, 形成不包含0的新数组"></a>2. 数组去0, 将数组中0去掉, 形成不包含0的新数组</h5><ol><li>声明一个新数组用于存放新数据num2</li><li>遍历原来的旧数组, 找出不等于0的元素</li><li>依次追加给新数组num2</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">2</span>, <span class="number">0</span>, <span class="number">6</span>, <span class="number">1</span>, <span class="number">77</span>, <span class="number">0</span>, <span class="number">52</span>, <span class="number">0</span>, <span class="number">25</span>, <span class="number">7</span>]</span><br><span class="line"><span class="keyword">let</span> num2 = []</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num3 = <span class="number">0</span>; num3 &lt; num1.<span class="property">length</span>; num3++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num1[num3] !== <span class="number">0</span>) &#123;</span><br><span class="line">        num2.<span class="title function_">push</span>(num1[num3])</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(num2)</span><br></pre></td></tr></table></figure><h4 id="2-删-数组删除元素"><a href="#2-删-数组删除元素" class="headerlink" title="2. 删: 数组删除元素"></a>2. 删: 数组删除元素</h4><ol><li>数组. pop(): 从数组中<strong>删除最后一个元素</strong>, 并返回该元素的值</li><li>数组. shift(): 从数组中<strong>删除第一个元素</strong>, 并返回该元素的值</li><li>数组. splice(): 删除<strong>指定元素</strong></li><li>start: 起始位置, 指定修改的开始位置 <strong>(从0计数)</strong></li><li>deletecount: 删除数组的个数, 省略则默认从指定起始位置<strong>删除到最后</strong></li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">10</span>, <span class="number">20</span>, <span class="number">30</span>]</span><br><span class="line"><span class="comment">// 删除数组中最后一个元素</span></span><br><span class="line">num1.<span class="title function_">pop</span>()</span><br><span class="line"><span class="comment">// 删除数组中第一个元素</span></span><br><span class="line">num1.<span class="title function_">shift</span>()</span><br><span class="line"><span class="comment">// 从第三个元素删除到第六个元素</span></span><br><span class="line"><span class="comment">// num1.splice(start起始位置, deletecount删除几个元素)</span></span><br><span class="line">num1.<span class="title function_">splice</span>(<span class="number">3</span>, <span class="number">6</span>)</span><br><span class="line"><span class="comment">// 添加一个新数组并返回删除的元素</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num1.<span class="title function_">pop</span>())</span><br></pre></td></tr></table></figure><h4 id="3-删除元素的使用场景"><a href="#3-删除元素的使用场景" class="headerlink" title="3. 删除元素的使用场景:"></a>3. 删除元素的使用场景:</h4><ol><li>开发很常用, 比如随机抽奖、删除指定商品…</li><li>随机抽奖, 中奖用户需要从数组里删除, 不允许重复抽奖</li><li>点击删除按钮, 相关数据会从商品数据中删除 后期会用到删除操作, 特别是splice</li></ol><hr><h3 id="7-冒泡排序"><a href="#7-冒泡排序" class="headerlink" title="7. 冒泡排序:"></a>7. 冒泡排序:</h3><ol><li>冒泡排序是一种<strong>简单的排序算法</strong></li><li>它<strong>重复的走访要排序的数列</strong>, <strong>一次比较两个元素</strong>, 如果它们<strong>顺序错误就把它交换过来</strong>, 走访数列的工作是<strong>重复的进行直到没有再需要交换</strong>, 也就是说该数列已经排序完成</li><li>这个算法名字由来是因为越小元素会由交换慢慢 ‘浮’ 到数列的顶端</li><li>比如数组 [2,3,1,4,5] 经过排序成为了 [1,2,3,4,5] 或者 [5,4,3,2,1]</li></ol><img src="" data-lazy-src="https://cdn.staticaly.com/gh/web-xc/iMG@main/postss/冒泡排序.jpg" style="zoom:33%"><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = [<span class="number">5</span>, <span class="number">4</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">1</span>]</span><br><span class="line"><span class="comment">// 1.一共需要的趟数, 5个数据我们要走4趟, 用外层for循环</span></span><br><span class="line"><span class="comment">// 所以: 数组的长度减去1 length - 1</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num2 = <span class="number">0</span>; num2 &lt; num1.<span class="property">length</span> - <span class="number">1</span>; num2++) &#123;</span><br><span class="line">    <span class="comment">// 2.每一趟交换次数, 用内层循环 </span></span><br><span class="line">    <span class="comment">// 所以: 减去数组长度1 但我们从0开始, 就是 length - num2 - 1</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">let</span> num3 = <span class="number">0</span>; num3 &lt; num1.<span class="property">length</span> - num2 - <span class="number">1</span>; num3++) &#123;</span><br><span class="line">        <span class="comment">// 3.if 做判断 0 大于 1 执行交换变量</span></span><br><span class="line">        <span class="keyword">if</span> (num1[num3] &gt; num1[num3 + <span class="number">1</span>]) &#123;</span><br><span class="line">            <span class="comment">// 4.交换变量</span></span><br><span class="line">            <span class="keyword">let</span> temp = num1[num3]</span><br><span class="line">            num1[num3] = num1[num3 + <span class="number">1</span>]</span><br><span class="line">            num1[num3 + <span class="number">1</span>] = temp</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(num1)</span><br></pre></td></tr></table></figure><hr><h3 id="8-根据输入数据生成柱形图"><a href="#8-根据输入数据生成柱形图" class="headerlink" title="8. 根据输入数据生成柱形图"></a>8. 根据输入数据生成柱形图</h3><ol><li>需要输入4次，所以把4个数据放到一个数组里 num1[]</li><li>利用循环，弹出4次输入框，同时存到数组里面 num1[]</li><li>遍历改数组，根据数据生成4个柱形图，渲染打印到页面中</li><li>柱形图就是div盒子, 设置宽度固定, 高度是用户输入的数据</li><li>div里面包含显示的数字和第N季度</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 用循环弹出四次输入框, 会得到4个数据，放到num1数组里</span></span><br><span class="line"><span class="keyword">let</span> num1 = []</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> num2 = <span class="number">1</span>; num2 &lt;= <span class="number">4</span>; num2++) &#123;</span><br><span class="line">    num1.<span class="title function_">push</span>(<span class="title function_">prompt</span>(<span class="string">`请输入第<span class="subst">$&#123;num2&#125;</span>季度数据`</span>))</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num1)</span><br><span class="line"><span class="comment">// 注意渲染循环的是柱子</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">`&lt;div class =&quot;box&quot;&gt;`</span>)</span><br><span class="line"><span class="comment">// 循环4个柱子</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">let</span> num2 = <span class="number">0</span>; num2 &lt; num1.<span class="property">length</span>; num2++) &#123;</span><br><span class="line">        <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">`</span></span><br><span class="line"><span class="string">     &lt;div style=&quot;height: <span class="subst">$&#123;num1[num2]&#125;</span>px;&quot;&gt;</span></span><br><span class="line"><span class="string">        &lt;span&gt;<span class="subst">$&#123;num1[num2]&#125;</span>&lt;/span&gt;</span></span><br><span class="line"><span class="string">        &lt;h4&gt;第<span class="subst">$&#123;num2 + <span class="number">1</span>&#125;</span>季度&lt;/h4&gt;</span></span><br><span class="line"><span class="string">     &lt;/div&gt;</span></span><br><span class="line"><span class="string">     `</span>)</span><br><span class="line">    &#125;</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">`&lt;/div&gt;`</span>)</span><br></pre></td></tr></table></figure><hr><h3 id="9-本节单词"><a href="#9-本节单词" class="headerlink" title="9. 本节单词:"></a>9. 本节单词:</h3><ol><li>for</li><li>array</li><li>arr</li><li>push</li><li>unshift</li><li>pop</li><li>shift</li><li>splice</li><li>continue</li><li>break</li><li>start</li><li>deletecount</li></ol></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">本文作者:</span> <span class="post-copyright-info"><a href="https://webxc.eu.org">XC's Blog</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">本文链接:</span> <span class="post-copyright-info"><a href="https://webxc.eu.org/post/6e+47/">https://webxc.eu.org/post/6e+47/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明:</span> <span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://webxc.eu.org" target="_blank">XC's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/JavaScript%E7%AC%94%E8%AE%B0/">JavaScript笔记</a></div><div class="post_share"><div class="social-share" data-image="https://npm.elemecdn.com/webxc/cover/js1.webp" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload='this.media="all"'><script src="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" alt="Wechat"></a><div class="post-qr-code-desc">Wechat</div></li><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" alt="Alipay"></a><div class="post-qr-code-desc">Alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/post/623e/"><img class="prev-cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇文章</div><div class="prev_info">JavaScript 第二天</div></div></a></div><div class="next-post pull-right"><a href="/post/7f86/"><img class="next-cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇文章</div><div class="next_info">JavaScript 第四天</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/post/f244/" title="JavaScript 第一天"><img class="cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-11-22</div><div class="title">JavaScript 第一天</div></div></a></div><div><a href="/post/623e/" title="JavaScript 第二天"><img class="cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-12-05</div><div class="title">JavaScript 第二天</div></div></a></div><div><a href="/post/fd38/" title="JavaScript 第五天"><img class="cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-02-16</div><div class="title">JavaScript 第五天</div></div></a></div></div></div><hr><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="author-info__name">XC's Blog</div><div class="author-info__description">XC's Blog 记录生活和学习文章</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">95</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://tenapi.cn/qqzlk/?qq=2848141597" target="_blank" title="QQ"><i class="iconfont icon-QQ"></i></a><a class="social-icon" href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.jpg" target="_blank" title="微信"><i class="iconfont icon-weixin"></i></a><a class="social-icon" href="https://github.com/web-xc" target="_blank" title="Github"><i class="iconfont icon-github"></i></a><a class="social-icon" href="https://space.bilibili.com/2134826455" target="_blank" title="BiliBili"><i class="iconfont icon-bilibili"></i></a><a class="social-icon" href="https://music.163.com/#/user/home?id=323682437" target="_blank" title="网易云音乐"><i class="iconfont icon-wyy"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">原网站因使用.ml域名被回收, 再加上本人因学习原因, 没怎么打理博客, 使用了https://webxc.eu.org域名来维持博客运行, 如果有加友联的朋友们, 去友联页看信息即可, 如果原来有加过的, 麻烦在原来域名后缀改一下(.ml ==> .eu.org)就行, 博客写的太乱了, 没时间打理, 兄弟们谅解😁😁~~</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#JavaScript-%E5%9F%BA%E7%A1%80%E7%AC%AC%E4%B8%89%E5%A4%A9-%E2%80%94-for-%E5%BE%AA%E7%8E%AF-%E5%92%8C-array%E6%95%B0%E7%BB%84"><span class="toc-number">1.</span> <span class="toc-text">JavaScript 基础第三天 — for 循环 和 array数组</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-for%E5%BE%AA%E7%8E%AF%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8"><span class="toc-number">2.</span> <span class="toc-text">1. for循环基本使用:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%BE%AA%E7%8E%AF%E9%80%80%E5%87%BA"><span class="toc-number">3.</span> <span class="toc-text">2. 循环退出:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-for-%E5%BE%AA%E7%8E%AF%E5%B5%8C%E5%A5%97"><span class="toc-number">4.</span> <span class="toc-text">3. for 循环嵌套:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E6%95%B0%E7%BB%84%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8"><span class="toc-number">5.</span> <span class="toc-text">4. 数组的基本使用:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-for-%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84"><span class="toc-number">6.</span> <span class="toc-text">5. for 遍历数组:</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E4%BD%BF%E7%94%A8for%E5%BE%AA%E7%8E%AF-%E6%B1%82%E6%95%B0%E7%BB%84%E7%9A%84-%E5%92%8C-x2F-%E5%B9%B3%E5%9D%87%E5%80%BC"><span class="toc-number">6.0.1.</span> <span class="toc-text">1. 使用for循环 求数组的 和&#x2F;平均值</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E4%BD%BF%E7%94%A8for%E5%BE%AA%E7%8E%AF-%E6%B1%82%E6%95%B0%E7%BB%84%E6%9C%80%E5%A4%A7%E5%80%BC"><span class="toc-number">6.0.2.</span> <span class="toc-text">2. 使用for循环 求数组最大值</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3-%E4%BD%BF%E7%94%A8for%E5%BE%AA%E7%8E%AF-%E6%B1%82%E6%95%B0%E7%BB%84%E4%B8%AD%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8E5%E7%9A%84%E5%92%8C-45"><span class="toc-number">6.0.3.</span> <span class="toc-text">3. 使用for循环 求数组中大于等于5的和 45</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-%E4%BD%BF%E7%94%A8for%E5%BE%AA%E7%8E%AF-%E8%AE%A1%E7%AE%97%E4%BB%A5%E4%B8%8B%E6%95%B0%E7%BB%84%E4%B8%AD%E8%83%BD%E8%A2%AB3%E6%95%B4%E9%99%A4%E7%9A%84%E5%81%B6%E6%95%B0%E7%9A%84%E5%92%8C-24"><span class="toc-number">6.0.4.</span> <span class="toc-text">4. 使用for循环 计算以下数组中能被3整除的偶数的和 24</span></a></li></ol></li></ol><li class="toc-item toc-level-3"><a class="toc-link" href="#6-%E6%93%8D%E4%BD%9C%E6%95%B0%E7%BB%84"><span class="toc-number">7.</span> <span class="toc-text">6. 操作数组:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%A2%9E%EF%BC%9A%E6%95%B0%E7%BB%84%E5%A2%9E%E5%8A%A0%E6%96%B0%E7%9A%84%E6%95%B0%E6%8D%AE"><span class="toc-number">7.1.</span> <span class="toc-text">1. 增：数组增加新的数据</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%EF%BC%91-%E6%95%B0%E7%BB%84%E7%AD%9B%E9%80%89-%E5%B0%86%E6%95%B0%E7%BB%84%E4%B8%AD%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8E10%E7%9A%84%E5%85%83%E7%B4%A0%E9%80%89%E5%87%BA%E6%9D%A5-%E6%94%BE%E5%85%A5%E6%96%B0%E6%95%B0%E7%BB%84"><span class="toc-number">7.1.1.</span> <span class="toc-text">１. 数组筛选, 将数组中大于等于10的元素选出来, 放入新数组</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E6%95%B0%E7%BB%84%E5%8E%BB0-%E5%B0%86%E6%95%B0%E7%BB%84%E4%B8%AD0%E5%8E%BB%E6%8E%89-%E5%BD%A2%E6%88%90%E4%B8%8D%E5%8C%85%E5%90%AB0%E7%9A%84%E6%96%B0%E6%95%B0%E7%BB%84"><span class="toc-number">7.1.2.</span> <span class="toc-text">2. 数组去0, 将数组中0去掉, 形成不包含0的新数组</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E5%88%A0-%E6%95%B0%E7%BB%84%E5%88%A0%E9%99%A4%E5%85%83%E7%B4%A0"><span class="toc-number">7.2.</span> <span class="toc-text">2. 删: 数组删除元素</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E5%88%A0%E9%99%A4%E5%85%83%E7%B4%A0%E7%9A%84%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF"><span class="toc-number">7.3.</span> <span class="toc-text">3. 删除元素的使用场景:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F"><span class="toc-number">8.</span> <span class="toc-text">7. 冒泡排序:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-%E6%A0%B9%E6%8D%AE%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE%E7%94%9F%E6%88%90%E6%9F%B1%E5%BD%A2%E5%9B%BE"><span class="toc-number">9.</span> <span class="toc-text">8. 根据输入数据生成柱形图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-%E6%9C%AC%E8%8A%82%E5%8D%95%E8%AF%8D"><span class="toc-number">10.</span> <span class="toc-text">9. 本节单词:</span></a></li></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/post/ds2s/" title="整个前端面试题"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="整个前端面试题"></a><div class="content"><a class="title" href="/post/ds2s/" title="整个前端面试题">整个前端面试题</a><time datetime="2023-08-31T02:00:00.000Z" title="发表于 2023-08-31 02:00:00">2023-08-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/ds23/" title="常见前端面试题"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="常见前端面试题"></a><div class="content"><a class="title" href="/post/ds23/" title="常见前端面试题">常见前端面试题</a><time datetime="2023-08-28T18:30:00.000Z" title="发表于 2023-08-28 18:30:00">2023-08-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/fe33/" title="硅谷甄选运营平台"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="硅谷甄选运营平台"></a><div class="content"><a class="title" href="/post/fe33/" title="硅谷甄选运营平台">硅谷甄选运营平台</a><time datetime="2023-07-26T03:55:00.000Z" title="发表于 2023-07-26 03:55:00">2023-07-26</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2023 By XC's Blog</div><div class="framework-info"><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/?keyword=20235221">萌ICP备20235221号</a><span class="footer-separator">|</span><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/">萌ICP查询</a><div id="running-time"></div></div><script>setInterval((()=>{let e=Math.round(new Date("2021-11-21 01:35:06").getTime()/1e3),t=Math.round(((new Date).getTime()+288e5)/1e3)-e,n=new Array(0,0,0,0,0);t>=31536e3&&(n[0]=parseInt(t/31536e3),t%=31536e3),t>=86400&&(n[1]=parseInt(t/86400),t%=86400),t>=3600&&(n[2]=parseInt(t/3600),t%=3600),t>=60&&(n[3]=parseInt(t/60),t%=60),t>0&&(n[4]=t),currentTimeHtml="本站已安全运行 "+n[0]+" 年 "+n[1]+" 天 "+n[2]+" 时 "+n[3]+" 分 "+n[4]+" 秒",document.getElementById("running-time").innerHTML=currentTimeHtml}),1e3)</script></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i><span id="percent">0<span>%</span></span></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight,500)"><i class="fas fa-arrow-down"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i> <span>正在载入文件,请稍后</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"></div></div><hr><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/utils.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/main.js"></script><script src="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://npm.elemecdn.com/instant.page/instantpage.js" type="module"></script><script src="https://npm.elemecdn.com/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/search/local-search.js"></script><div class="js-pjax"><script>(()=>{const e=document.querySelectorAll("#article-container .mermaid-wrap");if(e.length){window.runMermaid=()=>{window.loadMermaid=!0;const t="dark"===document.documentElement.getAttribute("data-theme")?"dark":"default";Array.from(e).forEach(((e,n)=>{const d=e.firstElementChild,r="mermaid-"+n,m="%%{init:{ 'theme':'"+t+"'}}%%\n"+d.textContent;mermaid.mermaidAPI.render(r,m,(e=>{d.insertAdjacentHTML("afterend",e)}))}))};const t=()=>{window.loadMermaid?runMermaid():getScript("https://npm.elemecdn.com/mermaid/dist/mermaid.min.js").then(runMermaid)};window.pjax?t():document.addEventListener("DOMContentLoaded",t)}})()</script><script>(()=>{const o=()=>{twikoo.init(Object.assign({el:"#twikoo-wrap",envId:"https://blog2.webxc.eu.org/",region:"",onCommentLoaded:function(){btf.loadLightbox(document.querySelectorAll("#twikoo .tk-content img:not(.tk-owo-emotion)"))}},null))},t=()=>{"object"!=typeof twikoo?getScript("https://npm.elemecdn.com/twikoo@1.6.16/dist/twikoo.all.min.js").then(o):setTimeout(o,0)};t()})()</script></div><script data-pjax="false" defer src="https://npm.elemecdn.com/webxc@1.0.16/css/style.js"></script><script defer src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/search/local-search.js"></scrip><script src="https://npm.elemecdn.com/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!0,POWERMODE.mobile=!0,document.body.addEventListener("input",POWERMODE)</script><script src="https://npm.elemecdn.com/pjax@0.2.8/pjax.min.js"></script><script>let pjaxSelectors=["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax",".tk-comments-container"];var pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!1,scrollRestoration:!1});document.addEventListener("pjax:send",(function(){if(window.tocScrollFn&&window.removeEventListener("scroll",window.tocScrollFn),window.scrollCollect&&window.removeEventListener("scroll",scrollCollect),"object"==typeof preloader&&preloader.initLoading(),document.getElementById("rightside").style.cssText="opacity: ''; transform: ''",window.aplayers)for(let e=0;e<window.aplayers.length;e++)window.aplayers[e].options.fixed||window.aplayers[e].destroy();"object"==typeof typed&&typed.destroy();const e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode"),"object"==typeof disqusjs&&disqusjs.destroy()})),document.addEventListener("pjax:complete",(function(){window.refreshFn(),document.querySelectorAll("script[data-pjax]").forEach((e=>{const t=document.createElement("script"),o=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(o)),e.parentNode.replaceChild(t,e)})),GLOBAL_CONFIG.islazyload&&window.lazyLoadInstance.update(),"function"==typeof chatBtnFn&&chatBtnFn(),"function"==typeof panguInit&&panguInit(),"function"==typeof gtag&&gtag("config","",{page_path:window.location.pathname}),"object"==typeof _hmt&&_hmt.push(["_trackPageview",window.location.pathname]),"function"==typeof loadMeting&&document.getElementsByClassName("aplayer").length&&loadMeting(),"object"==typeof Prism&&Prism.highlightAll(),"object"==typeof preloader&&preloader.endLoading()})),document.addEventListener("pjax:error",(e=>{404===e.request.status&&pjax.loadUrl("/404.html")}))</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script data-pjax>function butterfly_swiper_injector_config(){var s=document.getElementById("recent-posts");console.log("已挂载butterfly_swiper"),s.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-08-31</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ds2s/&quot;);" href="javascript:void(0);" alt="">整个前端面试题</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-08-28</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ds23/&quot;);" href="javascript:void(0);" alt="">常见前端面试题</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-26</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe33/&quot;);" href="javascript:void(0);" alt="">硅谷甄选运营平台</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-17</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ew32/&quot;);" href="javascript:void(0);" alt="">Vue第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-16</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/aw92/&quot;);" href="javascript:void(0);" alt="">Vue第二天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-14</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ou67/&quot;);" href="javascript:void(0);" alt="">Vue第一天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-05</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fn32/&quot;);" href="javascript:void(0);" alt="">Vue框架笔记</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-21</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe11/&quot;);" href="javascript:void(0);" alt="">Vue前置JS功底</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/promise.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/pr67/&quot;);" href="javascript:void(0);" alt="">ES6-Promise语法与原理</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-08</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/or01/&quot;);" href="javascript:void(0);" alt="">Ajax第四天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-07</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fs67/&quot;);" href="javascript:void(0);" alt="">Ajax第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe66/&quot;);" href="javascript:void(0);" alt="">JS进阶第四天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-10</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe99/&quot;);" href="javascript:void(0);" alt="">JS进阶第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-05</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/us87/&quot;);" href="javascript:void(0);" alt="">JS进阶第二天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover15.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-10-31</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/2db5/&quot;);" href="javascript:void(0);" alt="">移动开发-Flex布局</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover16.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-14</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/1c7e/&quot;);" href="javascript:void(0);" alt="">移动开发-媒体查询</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover17.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-17</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/7fc/&quot;);" href="javascript:void(0);" alt="">移动开发-响应式</a><div class="blog-slider__text">点击查看</div></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div></div>')}for(var elist="null".split(","),cpage=location.pathname,epage="all",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_swiper_injector_config()</script><script defer src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper_init.js"></script></body></html>